package com.naizhuai.ui.user.userinfo;

import android.support.annotation.NonNull;

import com.naizhuai.Model.ModelProvider;
import com.naizhuai.Model.db.user.PersonUserBean;
import com.naizhuai.Model.db.user.UserDataSourse;
import com.naizhuai.network.NetWorkObserver;
import com.naizhuai.ui.entity.setting.UserAbilityLabels;
import com.naizhuai.ui.mianbusiness.setting.presenter.UserPersonalApiStoreIml;

import rx.Observer;

/**
 * @author：lichenxi
 * @date 2018/2/27 19
 * email：525603977@qq.com
 * Fighting
 */
public class InfoPresenter implements InfoContract.Presenter {
    private @NonNull UserDataSourse mUserRepository;
    private @NonNull InfoContract.View mInfoView;
    private String uid;
    public InfoPresenter(String uid) {
        this.uid=uid;
        this.mUserRepository = ModelProvider.provideUserRepository();
    }

    @Override
    public void takeView(@NonNull InfoContract.View view) {
       this.mInfoView=view;

    }

    @Override
    public void populateUserInfo() {
        mUserRepository.getUserAsyn(uid,new UserDataSourse.GetUserCallback() {
            @Override
            public void onUserLoaded(PersonUserBean user) {
               mInfoView.showUserInfo(user);
            }

            @Override
            public void onDataNotAvailable() {
                mInfoView.userDataError();
            }
        });
        UserPersonalApiStoreIml.getInstance().getGrowById(uid)
                .subscribe(new NetWorkObserver<UserAbilityLabels>() {
                    @Override
                    public void onFail(String errormsg) {

                    }

                    @Override
                    public void onSuccess(UserAbilityLabels result) {
                        mInfoView.showTitleHeader(result);
                    }
                });

    }


    @Override
    public void dropView() {
        mInfoView=null;
    }
}
